﻿namespace OpenPms.Data;

public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
    { }
    public DbSet<TTest> Tests { get; set; }
    public DbSet<TTestSon> TestsSons { get; set; }

    //public DbSet<THotel> Hotels { get; set; }
    public DbSet<TWXMsg> WXMsgs { get; set; }
    public DbSet<TRoomType> RoomTypes { get; set; }
    public DbSet<TRoom> Rooms { get; set; }
    /// <summary>
    /// 已预订的房间数量
    /// </summary>
    public DbSet<TQuantity> Quantities { get; set; }

    public DbSet<TRate> Rates { get; set; }
    /// <summary>
    ///  ii.RateId, ii.Date, ii.RoomTypeId, ii.IsDelayPrice
    /// </summary>
    public DbSet<TPrice> Prices { get; set; }
    public DbSet<TReservation> Reservations { get; set; }
    public DbSet<TAccount> Accounts { get; set; }
    public DbSet<TOrder> Orders { get; set; }
    public DbSet<TGuest> Guests { get; set; }


    public DbSet<TArchiveReservation> ArchiveReservations { get; set; }
    public DbSet<TArchiveAccount> ArchiveAccounts { get; set; }
    public DbSet<TArchiveOrder> ArchiveOrders { get; set; }
    public DbSet<TArchiveGuest> ArchiveGuests { get; set; }
    protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
    {

        configurationBuilder.Properties<decimal>().HavePrecision(18, 2);


        base.ConfigureConventions(configurationBuilder);
    }
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {

        modelBuilder.Entity<TRoomType>().ToTable("RoomTypes", ii => ii.IsTemporal());
        modelBuilder.Entity<TRoom>().ToTable("Rooms", ii => ii.IsTemporal());
        modelBuilder.Entity<TRate>().ToTable("Rates", ii => ii.IsTemporal());
        modelBuilder.Entity<TPrice>().ToTable("Prices", ii => ii.IsTemporal());
        modelBuilder.Entity<TAccount>().ToTable("Accounts", ii => ii.IsTemporal());
        modelBuilder.Entity<TOrder>().ToTable("Orders", ii => ii.IsTemporal());
        modelBuilder.Entity<TReservation>().ToTable("Reservations", ii => ii.IsTemporal());
        modelBuilder.Entity<TGuest>().ToTable("Guests", ii => ii.IsTemporal());



        base.OnModelCreating(modelBuilder);
    }

}

